function e(e) {
    a.onShowData || (a.onShowData = {}), a.onShowData.scene = e;
}

var t = require("../../api.js"), a = getApp(), o = {
    init: function(o, r) {
        var i = this;
        i.page = o, a = r, i.page.orderPay = function(o) {
            function r(t, o, r) {
                t.pay_type = "WECHAT_PAY", a.request({
                    url: o,
                    data: t,
                    complete: function() {
                        wx.hideLoading();
                    },
                    success: function(t) {
                        0 == t.code && (e("pay"), wx.requestPayment({
                            _res: t,
                            timeStamp: t.data.timeStamp,
                            nonceStr: t.data.nonceStr,
                            package: t.data.package,
                            signType: t.data.signType,
                            paySign: t.data.paySign,
                            success: function(e) {},
                            fail: function(e) {},
                            complete: function(e) {
                                "requestPayment:fail" != e.errMsg && "requestPayment:fail cancel" != e.errMsg ? wx.redirectTo({
                                    url: "/" + r + "?status=1"
                                }) : wx.showModal({
                                    title: "提示",
                                    content: "订单尚未支付",
                                    showCancel: !1,
                                    confirmText: "确认",
                                    success: function(e) {
                                        e.confirm && wx.redirectTo({
                                            url: "/" + r + "?status=0"
                                        });
                                    }
                                });
                            }
                        })), 1 == t.code && wx.showToast({
                            title: t.msg,
                            image: "/images/icon-warning.png"
                        });
                    }
                });
            }
            function s(e, t, o) {
                e.pay_type = "BALANCE_PAY";
                var r = wx.getStorageSync("user_info");
                wx.showModal({
                    title: "当前账户余额：" + r.money,
                    content: "是否使用余额",
                    success: function(r) {
                        r.confirm && (wx.showLoading({
                            title: "正在提交",
                            mask: !0
                        }), a.request({
                            url: t,
                            data: e,
                            complete: function() {
                                wx.hideLoading();
                            },
                            success: function(e) {
                                0 == e.code && wx.redirectTo({
                                    url: "/" + o + "?status=1"
                                }), 1 == e.code && wx.showModal({
                                    title: "提示",
                                    content: e.msg,
                                    showCancel: !1
                                });
                            }
                        }));
                    }
                });
            }
            var n = o.currentTarget.dataset.index, d = i.page.data.order_list[n], c = new Array();
            if (void 0 !== i.page.data.pay_type_list) c = i.page.data.pay_type_list; else if (void 0 !== d.pay_type_list) c = d.pay_type_list; else if (void 0 !== d.goods_list[0].pay_type_list) c = d.goods_list[0].pay_type_list; else {
                var g = {};
                g.payment = 0, c.push(g);
            }
            var u = getCurrentPages(), p = u[u.length - 1].route, l = {};
            if (-1 != p.indexOf("pt")) _ = t.group.pay_data, l.order_id = d.order_id; else if (-1 != p.indexOf("miaosha")) _ = t.miaosha.pay_data, 
            l.order_id = d.order_id; else if (-1 != p.indexOf("book")) _ = t.book.order_pay, 
            l.id = d.id; else {
                var _ = t.order.pay_data;
                l.order_id = d.order_id;
            }
            1 == c.length ? (wx.showLoading({
                title: "正在提交",
                mask: !0
            }), 0 == c[0].payment && r(l, _, p), 3 == c[0].payment && s(l, _, p)) : wx.showModal({
                title: "提示",
                content: "选择支付方式",
                cancelText: "余额支付",
                confirmText: "线上支付",
                success: function(e) {
                    e.confirm ? (wx.showLoading({
                        title: "正在提交",
                        mask: !0
                    }), r(l, _, p)) : e.cancel && s(l, _, p);
                }
            });
        }, i.page.order_submit = function(r, s) {
            function n() {
                wx.showLoading({
                    title: "正在提交",
                    mask: !0
                }), a.request({
                    url: d,
                    method: "post",
                    data: r,
                    success: function(t) {
                        if (0 == t.code) {
                            var n = function() {
                                a.request({
                                    url: c,
                                    data: {
                                        order_id: d,
                                        order_id_list: u,
                                        pay_type: p,
                                        form_id: r.formId
                                    },
                                    success: function(e) {
                                        if (0 != e.code) return wx.hideLoading(), void wx.showModal({
                                            title: "提示",
                                            content: e.msg,
                                            showCancel: !1,
                                            confirmText: "确认",
                                            success: function(e) {
                                                e.confirm && wx.redirectTo({
                                                    url: g + "?status=0"
                                                });
                                            }
                                        });
                                        setTimeout(function() {
                                            wx.hideLoading();
                                        }, 1e3), "pt" == s ? "ONLY_BUY" == i.page.data.type ? wx.redirectTo({
                                            url: g + "?status=2"
                                        }) : wx.redirectTo({
                                            url: "/pt/group/details?oid=" + d
                                        }) : void 0 !== i.page.data.goods_card_list && i.page.data.goods_card_list.length > 0 && 2 != r.payment ? i.page.setData({
                                            show_card: !0
                                        }) : wx.redirectTo({
                                            url: g + "?status=-1"
                                        });
                                    }
                                });
                            };
                            if (void 0 != t.data.p_price && 0 === t.data.p_price) return o.showToast({
                                title: "提交成功"
                            }), void setTimeout(function() {
                                wx.navigateBack();
                            }, 2e3);
                            setTimeout(function() {
                                i.page.setData({
                                    options: {}
                                });
                            }, 1);
                            var d = t.data.order_id || "", u = t.data.order_id_list ? JSON.stringify(t.data.order_id_list) : "", p = "";
                            0 == r.payment ? a.request({
                                url: c,
                                data: {
                                    order_id: d,
                                    order_id_list: u,
                                    pay_type: "WECHAT_PAY"
                                },
                                success: function(t) {
                                    if (0 != t.code) {
                                        if (1 == t.code) return wx.hideLoading(), void i.page.showToast({
                                            title: t.msg,
                                            image: "/images/icon-warning.png"
                                        });
                                    } else {
                                        setTimeout(function() {
                                            wx.hideLoading();
                                        }, 1e3), e("pay"), t.data && 0 == t.data.price ? void 0 !== i.page.data.goods_card_list && i.page.data.goods_card_list.length > 0 ? i.page.setData({
                                            show_card: !0
                                        }) : wx.redirectTo({
                                            url: g + "?status=1"
                                        }) : wx.requestPayment({
                                            _res: t,
                                            timeStamp: t.data.timeStamp,
                                            nonceStr: t.data.nonceStr,
                                            package: t.data.package,
                                            signType: t.data.signType,
                                            paySign: t.data.paySign,
                                            success: function(e) {},
                                            fail: function(e) {},
                                            complete: function(e) {
                                                "requestPayment:fail" != e.errMsg && "requestPayment:fail cancel" != e.errMsg ? "requestPayment:ok" != e.errMsg || (void 0 !== i.page.data.goods_card_list && i.page.data.goods_card_list.length > 0 ? i.page.setData({
                                                    show_card: !0
                                                }) : "pt" == s ? "ONLY_BUY" == i.page.data.type ? wx.redirectTo({
                                                    url: g + "?status=2"
                                                }) : wx.redirectTo({
                                                    url: "/pt/group/details?oid=" + d
                                                }) : wx.redirectTo({
                                                    url: g + "?status=1"
                                                })) : wx.showModal({
                                                    title: "提示",
                                                    content: "订单尚未支付",
                                                    showCancel: !1,
                                                    confirmText: "确认",
                                                    success: function(e) {
                                                        e.confirm && wx.redirectTo({
                                                            url: g + "?status=0"
                                                        });
                                                    }
                                                });
                                            }
                                        });
                                        var a = wx.getStorageSync("quick_list");
                                        if (a) {
                                            for (var r = a.length, n = 0; n < r; n++) for (var c = a[n].goods, u = c.length, p = 0; p < u; p++) c[p].num = 0;
                                            wx.setStorageSync("quick_lists", a);
                                            for (var l = wx.getStorageSync("carGoods"), r = l.length, n = 0; n < r; n++) l[n].num = 0, 
                                            l[n].goods_price = 0, o.setData({
                                                carGoods: l
                                            });
                                            wx.setStorageSync("carGoods", l);
                                            var _ = wx.getStorageSync("total");
                                            _ && (_.total_num = 0, _.total_price = 0, wx.setStorageSync("total", _));
                                            wx.getStorageSync("check_num");
                                            0, wx.setStorageSync("check_num", 0);
                                            for (var m = wx.getStorageSync("quick_hot_goods_lists"), r = m.length, n = 0; n < r; n++) m[n].num = 0, 
                                            o.setData({
                                                quick_hot_goods_lists: m
                                            });
                                            wx.setStorageSync("quick_hot_goods_lists", m);
                                        }
                                    }
                                }
                            }) : 2 == r.payment ? (p = "HUODAO_PAY", n()) : 3 == r.payment && (p = "BALANCE_PAY", 
                            n());
                        }
                        if (1 == t.code) return wx.hideLoading(), void wx.showToast({
                            title: t.msg,
                            icon: 'none',
                            fail:function (t) {
                                console.log(t)
                            }
                        });
                    }
                });
            }
            var d = t.order.submit, c = t.order.pay_data, g = "/pages/order/order";
            if ("pt" == s ? (d = t.group.submit, c = t.group.pay_data, g = "/pt/order/order") : "ms" == s ? (d = t.miaosha.submit, 
            c = t.miaosha.pay_data, g = "/miaosha/order/order") : "pond" == s ? (d = t.pond.submit,
            c = t.order.pay_data, g = "/pages/order/order") : "scratch" == s ? (d = t.scratch.submit, 
            c = t.order.pay_data, g = "/pages/order/order") : "s" == s && (d = t.order.new_submit, 
            c = t.order.pay_data, g = "/pages/order/order"), 3 == r.payment) {
                var u = wx.getStorageSync("user_info");
                wx.showModal({
                    title: "当前账户余额：" + u.money,
                    content: "是否确定使用余额支付",
                    success: function(e) {
                        e.confirm && n();
                    }
                });
            } else n();
        };
    }
};

module.exports = o;